﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoiffeurProject.Utils;

namespace CoiffeurProject.DBMS.Entities
{
    public class Customer : Person
    {
        internal static int CURRENT_ID;
        internal static int FIELD_NUMBER = 8;

        int id;
        string name, surname, phone, address, sex, email, notes;
        DateTime birthday;

        public Customer(string name, string surname, string phone, string address, string sex, string email, string notes, DateTime birthday)
        {
            this.name = name;
            this.surname = surname;
            this.phone = phone;
            this.address = address;
            this.sex = sex;
            this.email = email;
            this.notes = notes;
            this.birthday = birthday;

            CURRENT_ID++;
            this.id = CURRENT_ID;
        }

        internal Customer(int id, string name, string surname, string phone, string address, string sex, string email, string notes, DateTime birthday)
        {
            this.name = name;
            this.surname = surname;
            this.phone = phone;
            this.address = address;
            this.sex = sex;
            this.email = email;
            this.notes = notes;
            this.birthday = birthday;
            this.id = id;
        }

        public void Update(string name, string surname, string phone, string address, string sex, string email, string notes, DateTime birthday)
        {
            this.name = name;
            this.surname = surname;
            this.phone = phone;
            this.address = address;
            this.sex = sex;
            this.email = email;
            this.notes = notes;
            this.birthday = birthday;
        }

        public override String ToString()
        {
            return id.ToString() + Constants.Separator + name + Constants.Separator + surname + Constants.Separator + phone +
                Constants.Separator + address + Constants.Separator + sex + Constants.Separator + email + Constants.Separator + 
                notes + Constants.Separator + birthday.ToCustomString();
        }

        #region Properties

        internal int Id
        {
            get { return id; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public string Surname
        {
            get { return surname; }
            set { surname = value; }
        }

        public string FullName
        {
            get { return name + " " + surname; }
        }

        public string Phone
        {
            get { return phone; }
            set { phone = value; }
        }

        public string Address
        {
            get { return address; }
            set { address = value; }
        }

        public string Sex
        {
            get { return sex; }
            set { sex = value; }
        }

        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        public string Notes
        {
            get { return notes; }
            set { notes = value; }
        }

        public DateTime Birthday
        {
            get { return birthday; }
            set { birthday = value; }
        }

        public string ShortBirthday
        {
            get { return birthday.Day + " " + birthday.MonthToString(); }
        }

        public int Age
        {
            get {
                int age = DateTime.Now.Year - birthday.Year;

                if ((DateTime.Now.Month < birthday.Month) || (DateTime.Now.Month == birthday.Month && DateTime.Now.Day < birthday.Day))
                    age--;

                return age;
            }
        }

        public bool NextToBirthday()
        {
            var curr_date = DateTime.Now;

            return (curr_date.Month == birthday.Month && (curr_date.Day == birthday.Day || 
                curr_date.Day == birthday.Day - 1 || curr_date.Day == birthday.Day - 2));
        }

        #warning Da implementare
        public int Frequency
        {
            get { return 0; }
        }

        public String FormatedAddress
        {
            get { return address; }
        }

        public Boolean Debtor
        {
            get { return true; }
        }

        #endregion
    }
}
